//
//  AMPCoreUtils.swift
//  LivingHelper
//
//  Created by Ampaw on 2017/9/9.
//  Copyright © 2017年 Ampaw. All rights reserved.
//

import UIKit

class AMPCoreUtils: NSObject {
    
    /**
     设置控件frame
     
     *  @ parameter x:  x轴
     *  @ parameter y:  y轴
     
     *  @ returns: CGRect
     */
    static func AMPFrame(_ x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat) -> CGRect {
        return CGRect(x: x, y: y, width: width, height: height)
    }
    
    /**
     *  颜色
     */
    static func AMPColor(_ r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat) -> (UIColor) {
        return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
    }
    
    /**
     返回按钮
     
     *  @ parameter sel: 事件
     *  @ returns: 按钮
     
     self.navigationItem.leftBarButtonItem = Constants.HDBackBarButtonItem("doThing:", taget: self)
     */
    static func AMPBackBarButtonItem(_ sel:Selector, taget:AnyObject) -> (UIBarButtonItem) {
        
        let button = UIButton(type: UIButtonType.custom) as UIButton
        button.frame = CGRect(x: 0, y: 0, width: 10, height: 20)
        button.setBackgroundImage(UIImage(named: "back_icon_white"), for: UIControlState.normal)
        button.addTarget(taget, action: sel, for: UIControlEvents.touchUpInside)
        button.contentMode = UIViewContentMode.scaleToFill
        
        let backItem = UIBarButtonItem(customView: button)
        return backItem
    }

}
